package org.bite.springmvcdemo;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String userName, String passWord, HttpSession session ){
        //参数检验
//        if(username == null || username.equals("")){
//            return false;
//        }
/*        if(StringUtils.hasLength(username) && StringUtils.hasLength(password)){
            if("zhangsan".equals(username) && "123456".equals(password)){
                return true;
            }
        }*/
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(passWord)){
            return false;
        }
        if("zhangsan".equals(userName) && "123456".equals(passWord)){
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }

    @RequestMapping("/getUserInfo")
    public String getUserInfo(HttpSession session){
        String userName = (String) session.getAttribute("userName");
        System.out.println("登录用户"+userName);
        return userName;
    }
}
